﻿using System;
using System.Collections;
using System.Collections.Specialized;
using System.Data;
using System.Data.SqlTypes;
using System.Data.SqlClient;
using System.Text;
using ECommerce.DAL;

namespace Entity
{
    /// <summary>
    /// This object represents the Private Fields of TblProductReview.
    /// </summary>
    
    public partial class TblProductReview : DatabaseUtility
    {
        string _productName = String.Empty;
        public string ProductName
        {
            get
            {
                if(String.IsNullOrEmpty(_productName))
                    _productName = TblProduct.GetTblProductByProductId(this._productId).ProductName;
                return _productName;
                //return "Test";
            }
        }

        public static CustomCollection<TblProductReview> GetAllProductReviewsWithProductPaged(string orderBy, int startRowIndex, int maximumRows)
        {
            //Validate Input
            if (orderBy == "")
                orderBy = "ProductReviewId";

            // Execute SQL Command
            SqlCommand sqlCmd = new SqlCommand();
            AddParameterToSqlCmd(sqlCmd, "@orderby", SqlDbType.VarChar, 50, ParameterDirection.Input, orderBy);
            AddParameterToSqlCmd(sqlCmd, "@startrow", SqlDbType.Int, 0, ParameterDirection.Input, startRowIndex);
            AddParameterToSqlCmd(sqlCmd, "@pagesize", SqlDbType.Int, 0, ParameterDirection.Input, maximumRows);

            SetCommandType(sqlCmd, CommandType.StoredProcedure, "spr_TblProductReview_GetAllProductReviewsWithProductPaged");

            GenerateCollectionFromReader test = new GenerateCollectionFromReader(GenerateTblProductReviewCollectionFromReader);
            CustomCollection<TblProductReview> objCollection = ((CustomCollection<TblProductReview>)ExecuteReaderCmd(sqlCmd, test));
            return objCollection;
        }

        public static int GetAllProductReviewsWithProductPagedCount()
        {
            return TblProductReview.GetAllTblProductReviewPagedCount("", 0, 0);
        }

        public static CustomCollection<TblProductReview> GetAllApprovedProductReviewsPaged(string orderBy, int startRowIndex, int maximumRows)
        {
            //Validate Input
            if (orderBy == "")
                orderBy = "ProductReviewId";

            // Execute SQL Command
            SqlCommand sqlCmd = new SqlCommand();
            AddParameterToSqlCmd(sqlCmd, "@orderby", SqlDbType.VarChar, 50, ParameterDirection.Input, orderBy);
            AddParameterToSqlCmd(sqlCmd, "@startrow", SqlDbType.Int, 0, ParameterDirection.Input, startRowIndex);
            AddParameterToSqlCmd(sqlCmd, "@pagesize", SqlDbType.Int, 0, ParameterDirection.Input, maximumRows);

            SetCommandType(sqlCmd, CommandType.StoredProcedure, "spr_TblProductReview_GetAllApprovedTblProductReviewsPaged");

            GenerateCollectionFromReader test = new GenerateCollectionFromReader(GenerateTblProductReviewCollectionFromReader);
            CustomCollection<TblProductReview> objCollection = ((CustomCollection<TblProductReview>)ExecuteReaderCmd(sqlCmd, test));
            return objCollection;
        }

        public static int GetAllApprovedProductReviewsPagedCount()
        {
            // Execute SQL Command
            SqlCommand sqlCmd = new SqlCommand();

            AddParameterToSqlCmd(sqlCmd, "@ReturnValue", SqlDbType.Int, 0, ParameterDirection.ReturnValue, null);
            SetCommandType(sqlCmd, CommandType.StoredProcedure, "spr_TblProductReview_GetAllApprovedTblProductReviewsPagedCount");
            ExecuteScalarCmd(sqlCmd);

            int returnValue = (int)sqlCmd.Parameters["@ReturnValue"].Value;
            return returnValue;
        }
    }
}
